<template>
	<div class="g-state">{{text}}</div>
</template>

<script type="text/javascript">
import constant from '@/common/constant'
import remoteDAO from '@/common/remoteDAO'
// import tools from 'libs/common/tools'
import { destruct } from '@/common/common'

export default {
  name: 'state',
  data () {
    return {
      text: ''
    }
  },
  props: {
    type: {
      default: null
    },
    rapidNum: {
      default: null
    }
  },
  watch: {
    rapidNum: function (val) {
      this.fetchChange();
    }
  },
  methods: {
    async fetchFund() {
      const res = await remoteDAO.invoke(constant.InterfaceEnum.GET_OVER_ALL_FINANCE);

      const val = this.type == 0 ? res.market
        : this.type == 6 ? res.dd
        : this.type == 4 ? res.hgt
        : this.type == 5 ? res.sgt : ''

      val.ljjlr = val.ljjlr || val.ddljjlr || 0;

      const reverse = (val.ljjlr > 0 && val.je < 0) || (val.ljjlr < 0 && val.je > 0)
      const m = reverse ? '' : destruct(val.je + val.ljjlr);
      this.text = reverse ? `结束${val.days}日连续${Number(val.je) > 0 ? '净流入' : '净流出'}态势`
        : `连续${val.days + 1}日${m.isNegative ? '净流出' : '净流入'}，累计${m.isNegative ? '流出' : '流入'}${m.num}${m.unit}`;
    },
    async fetchChange() {
      const rapidNum = this.rapidNum || 0;
      const res = await remoteDAO.invoke(constant.InterfaceEnum.GET_CHG_STAT);
      const current = await remoteDAO.invoke(constant.InterfaceEnum.GET_RAPID_CHANGE);

      let rise, fall;
      this.type == 7 ? ({ nULN: rise, nDLN: fall } = current) : ({ nRTUN: rise, nRTDN: fall } = current);
      const jz = this.type == 7 ? rise - fall : rapidNum;
      const [upText, downText] = this.type == 7 ? ['净涨停', '净跌停'] : ['净急涨', '净急跌']
      const days = res.flagUpDown ? res.nowUpTrend : res.nowDownTrend
      const reverse = (res.flagUpDown && jz < 0) || (!res.flagUpDown && jz > 0)
      this.text = reverse ? `结束${days}日连续${res.flagUpDown ? upText : downText}态势`
        : `${this.type == 7 ? '当前' : '当日'}${jz >= 0 ? upText : downText}${Math.abs(jz)}只 , 连续${Number(days) + 1}日${res.flagUpDown ? upText : downText}`;
    }
  },
  mounted() {
    this.type == null ? ''
      : this.type <= 6 ? this.$loop.register(this.fetchFund)
      : this.type == 7 ? this.$loop.register(this.fetchChange)
      : '';
  }
}
</script>

<style lang="less" scoped>
	@import '../../assets/css/variables.less';

	.g-state {
    display: flex;
    justify-content: center;
    align-items: center;
		background-color: @blue-e;
		color: white;
    font:.12rem/1 PingFangSC;
    height: .25rem;
    white-space: nowrap;
    overflow-x: auto;
	}
  ::-webkit-scrollbar{
    display:none;
  }
</style>
